/*
 * @lc app=leetcode.cn id=1491 lang=typescript
 *
 * [1491] 去掉最低工资和最高工资后的工资平均值
 */

// @lc code=start
function average(salary: number[]): number {
    let top = 0;
    let down = Infinity;
    let sum = 0;
    for (let i = 0; i < salary.length; i++) {
        const element = salary[i];
        top = Math.max(top, element);
        down = Math.min(down, element);
        sum += element;
    }
    return (sum - top - down) / (salary.length - 2);
}
// @lc code=end
